<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>8.字符串替换标题关键词</title>
</head>

<body>
  <script>
    const hd = "houdunren.com";
    console.log(hd.replace('houdunren', 'hdcms'));

    const words = ["php", "css"];
    const string = "我喜欢在后盾人学习php与css知识";
     // 遍历数组
    const title = words.reduce((pre, word) =>
      //数组会循环两次，因为数组长度为2，最后一次会返回 return 后面跟的字符串。
      pre.replace(word, `<a href="?w=${word}">${word}</a>`)
      , string);
    document.body.innerHTML += title;
  </script>
</body>

</html>